package com.example.gobang.mapper;

import com.example.gobang.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    // 根据用户名查找用户信息
    @Select("select * from user_info where user_name = #{userName};")
    UserInfo selectByName(String userName);
    // 根据用户 id 查找用户信息
    @Select("select * from user_info where user_id = #{userId};")
    UserInfo selectById(int userId);
    @Update("update user_info set total_count = total_count + 1, win_count = win_count + 1, score = score + 30 " +
            " where user_id = #{userId}")
    int userWin(int winner);

    @Update("update user_info set total_count = total_count + 1, score = score - 30 " +
            " where user_id = #{userId}")
    int userLose(int loser);

    @Insert("insert into user_info (user_name, password, score, total_count, win_count) values (#{userName}, #{password}, 1000, 0, 0)")
    int insertUser(String userName, String password);
}
